package com.smartcanteen.setmeal.mapper;

import com.github.pagehelper.Page;

import com.smartcanteen.annotation.AutoFill;
import com.smartcanteen.enumeration.OperationType;
import com.smartcanteen.setmeal.domain.dto.SetmealPageDTO;
import com.smartcanteen.setmeal.domain.entity.Setmeal;
import com.smartcanteen.system.api.domain.vo.DishItemVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @AutoFill(OperationType.INSERT)
    void addSetmeal(Setmeal setmeal);

    Page<Setmeal> getPageList(SetmealPageDTO setmealPageDTO);

    @Select("select * from sc_setmeal where id = #{id}")
    Setmeal getSetmealById(Integer id);

    @Select("select * from sc_setmeal where category_id = #{id}")
    Setmeal getSetmealByCategoryId(Integer id);

    @Update("update sc_setmeal set status = IF(status = 1, 0, 1) where id = #{id}")
    void onOff(Integer id);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    void deleteBatch(@Param("ids") List<Integer> ids);

    List<Setmeal> getList(Setmeal setmeal);

    @Select("select s.name, s.image, s.description, sd.copies from " +
            "sc_setmeal s left join sc_setmeal_dish sd on s.id = sd.dish_id " +
            "where sd.setmeal_id = #{id}")
    List<DishItemVO> getSetmealDishesById(Integer id);

    @Select("select count(id) from sc_setmeal where status = #{i}")
    Integer getByStatus(int i);
}
